﻿using RecruitStudents.Utility;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Json;
using RecruitStudents.Utility.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RecruitStudents.Client.BLL
{
    class ServiceConsult
    {
        WS_Consult.ConsultService consultService = new WS_Consult.ConsultService();
        WS_Consult.MySoapHeader objHeader = new WS_Consult.MySoapHeader();
        internal ServiceConsult()
        {
            objHeader.Username = "admin";
            objHeader.Password = "xy";
            consultService.MySoapHeaderValue = objHeader;
        }

        #region 获取 待回复问题列表
        internal DataTable GetWaitResponseProblemTable(string strSignUpID, string strIsTop, string strIsStudent, string strIsFee, string strConsultResorce)
        {
            return consultService.GetWaitResponseProblemTable(strSignUpID, strIsTop, strIsStudent, strIsFee, strConsultResorce).ToDataTable();
        }
        #endregion

        #region 获取 已回复问题列表
        internal DataTable GetRepliedProblemTable(string strSignUpID, string strIsTop, string strIsFee, string strIsStudent,
            string strConsultResorce, string strConsultTitle, string strUsersNickName)
        {
            return consultService.GetRepliedProblemTable(strSignUpID, strIsTop, strIsFee, strIsStudent, strConsultResorce, strConsultTitle, strUsersNickName).ToDataTable();
        }

        #endregion

        #region 获取 回复区展示
        internal DataTable GetReplyAreaShow(string strTopicID)
        {
            return consultService.GetReplyAreaShow(strTopicID).ToDataTable();
        }
        #endregion


        #region 保存咨询互动回复表 更新咨询互动标题表
        internal bool SaveConsultReply_UpdateConsultTitle(string strMsgID, string strRichSend, string strUserName, string strSend, string strUserID, string strZX)
        {
            try
            {
                DevHelper.ShowWaiting();
                var result = consultService.SaveConsultReply_UpdateConsultTitle(strMsgID, strRichSend, strUserName, strSend, strUserID, strZX).ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }

            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }
        #endregion

        #region  设置不公开
        internal bool UpdateIsPublic(string strMsgID, string strIsinternal)
        {
            try
            {
                DevHelper.ShowWaiting();
                var result = consultService.UpdateIsPublic(strMsgID, strIsinternal).ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }
        #endregion

        #region  删除咨询互动列表
        internal bool DeleteConsultTitle(string strMsgID)
        {
            try
            {
                DevHelper.ShowWaiting();
                var result = consultService.DeleteConsultTitle(strMsgID).ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }

            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }
        #endregion

        #region  设置置顶
        internal bool UpdateIsTop(string strMsgID, string strIsTop)
        {
            try
            {
                DevHelper.ShowWaiting();
                var result = consultService.UpdateIsTop(strMsgID, strIsTop).ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }
        #endregion

        internal DataTable GetConsultTitleByID(string strID)
        {
            return consultService.GetConsultTitleByID(strID).ToDataTable();

        }

        internal DataTable GetDicMsgTypeTable(string strName)
        {
            DevHelper.ShowWaiting();
            using (DataTable result = consultService.GetDicMsgTypeTable(strName).ToDataTable())
            {
                if (result != null)
                {
                    foreach (DataRow dr in result.Rows)

                    if (dr["State"].ToSafeString() == "1")
                    {
                        dr["State"] = "有效";
                    }
                    else
                    {
                        dr["State"] = "无效";
                    }
            }
            return result;
        }
        }

        internal TB_ConsultType GetDicMsgTypeModel(string strConsultTypeID)
        {
            return consultService.GetDicMsgTypeModel(strConsultTypeID).ToList<TB_ConsultType>();
        }

        internal bool SaveDicMsgType(TB_ConsultType model)
        {
            try
            {
                DevHelper.ShowWaiting();
                var message = consultService.SaveDicMsgType(model.ToJson()).ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (message.State.ToLower() == "false")
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }

        internal DataTable GetNoticeTable(string strSignUpID)
        {
            return consultService.GetNoticeTable(strSignUpID).ToDataTable();
        }

        internal bool SaveNoticeList(List<TB_Notice> list)
        {
            try
            {
                DevHelper.ShowWaiting();
                var message = consultService.SaveNoticeList(list.ToJson()).ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (message.State.ToLower() == "false")
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.HideWaiting();
                return false;
            }
        }
    }
}
